# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Lucas Werkmeister <mail@lucaswerkmeister.de>
# Contributor: Dave Reisner <dreisner@archlinux.org>

pkgname=mkosi
pkgver=19
pkgrel=1
pkgdesc="Build Legacy-Free OS Images"
arch=(any)
url="https://github.com/systemd/mkosi"
license=(LGPL-2.1-or-later)
depends=(
  bubblewrap
  python
  python-argcomplete
  systemd
)
makedepends=(
#  pandoc-cli
  python-build
  python-installer
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(
  python-pytest
)
optdepends=(
  'acl: for removing directories created by mkosi'
  'apt: for creating Debian and Ubuntu images'
  'btrfs-progs: raw_btrfs and subvolume output formats'
  'cpio: for cpio output format'
  'debian-archive-keyring: build Debian images'
  'dnf: for creating CentOS, Fedora, OpenMandriva, Mageia and OpenSUSE images'
  'edk2-ovmf: for running bootable images using QEMU'
  'erofs-tools: for EROFS support'
  'gnupg: for signing image checksums'
  'kmod: for images using Linux kernels'
  'mtools: for FAT support'
  'openssl: for UEFI SecureBoot'
  'python-pefile: for bootable images'
  'qemu: for running bootable images using QEMU'
  'sbsigntools: for UEFI SecureBoot'
  'swtpm: for adding software TPM when running bootable images using QEMU'
  'systemd-ukify: for Unified Kernel Image (UKI) support'
  'tar: for tar output format and Debian or Ubuntu images'
  'ubuntu-keyring: for building Ubuntu images'
  'xz: for compressing images with xz'
  'zstd: for compressing images with zstd'
  # 'zypper: for creating OpenSUSE images'  # TODO: package zypper
)
source=(
  $pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz
)
sha512sums=('8eb4e4af823299fdd6e9a077ec27be029656974ba0414b08ef226b5ccf7cd0a92d8bef4e475cdf05b86c3a0027c43be0f895af56a87df22502d2904cb0246ef4')
b2sums=('c97a0a2139c036b727d0cdd6686a7fa5393f62357d87b988f0a1a473367eb552de1ed6f82c1ca99c697ef72acb2fdf6aef7981bfa8dd5c6230b82ba84cbcfb7e')

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
#  pandoc -t man -s -o $pkgname/resources/$pkgname.1 $pkgname/resources/$pkgname.md
}

check() {
  cd $pkgname-$pkgver
#  pytest -vv
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
#  install -vDm 644 $pkgname/resources/$pkgname.1 -t "$pkgdir/usr/share/man/man1/"
  install -vDm 644 docs/*.md {NEWS,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
